using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks
{
    [TaskDescription("Chase the enemy")]
    [TaskCategory("Custom")]
    public class ActionChaseEnemy : Action
    {
        [Tooltip("The enemy to chase")]
        public Transform enemy;
        [Tooltip("The chase speed")]
        public float speed = 1f;

        public override TaskStatus OnUpdate()
        {
            if (Vector3.Distance(transform.position, enemy.position) > 0.01f)
            {
                transform.position = Vector3.MoveTowards(transform.position, enemy.position, speed * Time.deltaTime);
                transform.LookAt(enemy.position);

                return TaskStatus.Running;
            }
            else
            {
                return TaskStatus.Success;
            }
        }
    }
}